from django import http
from django.shortcuts import render

# Create your views here.
from django.views import View
from address.models import Area

class Areas(View):

    def get(self,request):
        try:
            addresses = Area.objects.all()
            province_list = []

            for province_model in addresses:
                province_list.append({'aid': province_model.id,
                                      'aname': province_model.name})

        except Exception as e:
            return http.JsonResponse({'code': 400,
                                  'errmsg': '数据错误'})

        return http.JsonResponse({"errmsg": "OK","errno": "0",
                                  "data": province_list})






